package cn.jobstart.data;

import cn.jobstart.common.StringUtil;
import cn.jobstart.enums.SchoolFlagEnum;
import cn.jobstart.modelExt.SchoolExt;
import cn.jobstart.pubInter.exception.SkException;
import cn.jobstart.service.ISchoolService;
import lombok.Data;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author sunke
 * @version 1.0
 * @Description
 * @date 2023-11-10 16:23
 */
@Data
@Component
public class DataUtil {


    @Resource
    private ISchoolService schoolService;
    private List<SchoolExt> schoolList = null;

    public String getSchoolLabelBySchoolName(String school) {
        if (StringUtil.isNullOrEmpty(school)) {
            return "";
        }
        List<SchoolExt> schoolList = getSchoolList();
        if (StringUtil.isNullOrEmpty(schoolList)) {
            return "";
        }
        for (SchoolExt schoolItem : schoolList) {
            if (StringUtil.isNullOrEmpty(schoolItem.getName())) {
                continue;
            }

            if(school.length()>schoolItem.getName().length()){
                if(school.indexOf(schoolItem.getName())>=0){
                    return SchoolFlagEnum.getDescByType(schoolItem.getFlag());
                }

            }else{
                if(schoolItem.getName().indexOf(school)>=0){
                    return SchoolFlagEnum.getDescByType(schoolItem.getFlag());
                }
            }

        }


        return "";


    }

    public List<SchoolExt> getSchoolList() {
        if (StringUtil.isNotObjEmpty(schoolList)) {

            return schoolList;
        }
        try {
            schoolList = schoolService.getAllList(null);
        } catch (SkException e) {

        }

        return schoolList;
    }
}
